package ui;

import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseTrackListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

public abstract class SwitchButton extends Label implements MouseListener, MouseTrackListener{
	protected boolean state;
	private Image A_deactive;
	private Image A_active;
	private Image B_deactive;
	private Image B_active;
	public SwitchButton(Composite parent, int style) {
		super(parent, style);
	}

	protected void Initial(Image A_deactive, Image A_active, Image B_deactive, Image B_active, boolean state) {
		this.A_active = A_active;
		this.A_deactive = A_deactive;
		this.B_active = B_active;
		this.B_deactive = B_deactive;
		this.state = state;
		if (state) {
			setImage(A_deactive);
		}else {
			setImage(B_deactive);
		}
		addMouseListener(this);
		addMouseTrackListener(this);
	}
	
	public void active() {
		if (state) {
			setImage(A_active);
		}else {
			setImage(B_active);
		}
	}
	
	public void active(boolean state) {
		this.state = state;
		if (state) {
			setImage(A_active);
		}else {
			setImage(B_active);
		}
	}
	
	public void deactive() {
		if (state) {
			setImage(A_deactive);
		}else {
			setImage(B_deactive);
		}
	}
	
	@Override
	protected void checkSubclass() {
	}

	@Override
	public void mouseEnter(MouseEvent e) {
		active();
	}

	@Override
	public void mouseExit(MouseEvent e) {
		deactive();
	}

	@Override
	public void mouseHover(MouseEvent e) {}

	@Override
	public void mouseDoubleClick(MouseEvent e) {}

	@Override
	public void mouseDown(MouseEvent e) {}

	@Override
	public void mouseUp(MouseEvent e) {
		state =! state;
		active();
	}
	
}
